package com.h52mm.zkclient;

import org.I0Itec.zkclient.IZkChildListener;
import org.I0Itec.zkclient.ZkClient;

import java.util.List;

public class GetChildrenSample {

    public static void main(String[] args) throws InterruptedException {
        ZkClient zkClient=new ZkClient("127.0.0.1:2181");
        System.out.println("ZooKeeper session established");
        List<String> children = zkClient.getChildren("/zkclient");
        System.out.println(children);
        //注册监听时间
        zkClient.subscribeChildChanges("/zkclient", new IZkChildListener() {
            @Override
            public void handleChildChange(String parentPath, List<String> currentChilds) throws Exception {
                System.out.println(parentPath + " ' child changed, currentChilds:" + currentChilds);
            }
        });

        zkClient.createPersistent("/zkclient/test_zk");
        Thread.sleep(1000);
        zkClient.delete("/zkclient/test_zk");
        Thread.sleep(1000);
        zkClient.delete("/zkclient");
        Thread.sleep(Integer.MAX_VALUE);
    }

}
